/// Use "ANES2019_replicationdata.dta"


//////////////////////////////////////////////////////////////////////////////////////////////////////////
/// MANUSCRIPT Table 2 (top few rows) /////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////

/// Cross-tab of grew up rural ("ruralgrow"), current rural resident ("rurallive") and binary rural identity ("rasocid_binary")
tab rasocid_binary if rurallive==1 & ruralgrow==1
tab rasocid_binary if rurallive==1 & ruralgrow==0
tab rasocid_binary if rurallive==0 & ruralgrow==1
tab rasocid_binary if rurallive==0 & ruralgrow==0
//////////////////////////////////////////////////////////////////////////////////////////////////////////



//////////////////////////////////////////////////////////////////////////////////////////////////////////
/// ONLINE APPENDIX Table S5 and Figure S1 ///////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////

/// "rasocid_binary" = rural identity (binary), "ruralres" = rural resident, "ruralgrow" = grew up in a rural area, "inc" = income level, "college" = college degree attained, "black" = Black respondent, "hisp" = Hispanic respondent, "white" = White respondent, "female" = Female respondent, "age" = age of respondent, "relig" = religious importance, "region" = Census region, "bornagain" = Born Again Christian, "weight" = survey weight

logit rasocid_binary ruralres ruralgrow [pweight=weight]
est store r1
logit rasocid_binary ruralres ruralgrow inc college black hisp white female age bornagain relig i.region [pweight=weight]
est store r2
logit rasocid_binary i.ruralres##i.ruralgrow inc college black hisp white female age bornagain relig i.region [pweight=weight]
est store r3
// Figure:
margins, at(ruralres=(0 1) ruralgrow=(0 1))
marginsplot, scheme(s1mono)

// Table:
esttab r1 r2 r3 using "Tableanes2019ruralid1.rtf", eform ///
        cells(b (star fmt(2) vacant("-")) se(par(( )))) ///
        starlevels(* 0.05 ** 0.01 *** 0.001) stats(r2 pr2 N)
//////////////////////////////////////////////////////////////////////////////////////////////////////////





//////////////////////////////////////////////////////////////////////////////////////////////////////////
/// ONLINE APPENDIX Table S7 ///////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////

/// "pid" = partisanship, "rasocid_binary" = rural identity (binary), "ruralres" = rural resident, "inc" = income level, "college" = college degree attained, "black" = Black respondent, "hisp" = Hispanic respondent, "white" = White respondent, "female" = Female respondent, "age" = age of respondent, "relig" = religious importance, "region" = Census region, "bornagain" = Born Again Christian, "weight" = survey weight, "rr" = racial resentment, "multicult" = multiculturalism

logit rasocid_binary inc college black hisp white female age bornagain relig i.region multicult [pweight=weight], or
logit rasocid_binary inc college black hisp white female age bornagain relig i.region multicult  [pweight=weight] if ruralres==1, or
est store a1
logit rasocid_binary inc college black hisp white female age bornagain relig i.region multicult  [pweight=weight] if ruralres==0, or
est store a2
logit rasocid_binary inc college hisp female age bornagain relig i.region multicult [pweight=weight] if ruralres==1 & white==1, or
est store a3w
logit rasocid_binary inc college hisp female age bornagain relig i.region multicult [pweight=weight] if ruralres==0 & white==1, or
est store a4w
logit rasocid_binary inc college black hisp white female age bornagain relig i.region multicult  ruralgrow [pweight=weight] if ruralres==1, or
est store a3
logit rasocid_binary inc college black hisp white female age bornagain relig i.region multicult  ruralgrow [pweight=weight] if ruralres==0, or
est store a4

		esttab a1 a2 a3w a4w a3 a4 using "Tableanes2019multi.rtf", eform ///
        cells(b (star fmt(2) vacant("-")) se(par(( )))) ///
        starlevels(* 0.05 ** 0.01 *** 0.001) stats(r2 pr2 N)
//////////////////////////////////////////////////////////////////////////////////////////////////////////





//////////////////////////////////////////////////////////////////////////////////////////////////////////
/// ONLINE APPENDIX Figures S7 and S8 ////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////

/// Multiculturalism ("multicult") by rural identity ("rasocid_binary") and rural category of currently rural and grew up rural, current rural only, grew up rural only, neither live in a rural area nor grew up in one ("ruralcat")
/// Note that if you run this, you will have to reopen the data file to run other analyses
collapse (mean) meanmulticult= multicult (sd) sdmulticult=multicult (count) n=multicult, by(ruralcat rasocid_binary)
generate himulticult = meanmulticult + invttail(n-1,0.025)*(sdmulticult / sqrt(n))
generate lowmulticult = meanmulticult - invttail(n-1,0.025)*(sdmulticult / sqrt(n))
graph bar meanmulticult, over(ruralcat) over(rasocid_binary)
graph bar meanmulticult, over(ruralcat) over(rasocid_binary) asyvars
graph twoway (bar meanmulticult rasocid_binary) (rcap himulticult lowmulticult rasocid_binary), by(ruralcat) scheme(s1mono)

/// Among whites ("white"): Multiculturalism ("multicult") by rural identity ("rasocid_binary") and rural category of currently rural and grew up rural, current rural only, grew up rural only, neither live in a rural area nor grew up in one ("ruralcat")
/// Note that if you run this, you will have to reopen the data file to run other analyses
drop if white != 1
collapse (mean) meanmulticult= multicult (sd) sdmulticult=multicult (count) n=multicult, by(ruralcat rasocid_binary)
generate himulticult = meanmulticult + invttail(n-1,0.025)*(sdmulticult / sqrt(n))
generate lowmulticult = meanmulticult - invttail(n-1,0.025)*(sdmulticult / sqrt(n))
graph bar meanmulticult, over(ruralcat) over(rasocid_binary)
graph bar meanmulticult, over(ruralcat) over(rasocid_binary) asyvars
graph twoway (bar meanmulticult rasocid_binary) (rcap himulticult lowmulticult rasocid_binary), by(ruralcat) scheme(s1mono)


/// Mean values listed in note:
tabstat multicult if ruralres==1 & ruralgrow==0 & rasocid_binary==1 &white==1
tabstat multicult if ruralres==1 & ruralgrow==0 & rasocid_binary==0  &white==1
tabstat multicult if ruralres==1 & ruralgrow==1 & rasocid_binary==1 &white==1
tabstat multicult if ruralres==1 & ruralgrow==1 & rasocid_binary==0 &white==1
tabstat multicult if ruralres==0 & ruralgrow==1 & rasocid_binary ==1 &white==1
tabstat multicult if ruralres==0 & ruralgrow==1 & rasocid_binary == 0 & white==1
tabstat multicult if ruralres==0 & ruralgrow==0 & rasocid_binary==1 & white==1
tabstat multicult if ruralres==0 & ruralgrow==0 & rasocid_binary==0 & white==1

tabstat multicult [aweight=weight] if ruralres==1 & ruralgrow==0 & rasocid_binary==1 & white==1
tabstat multicult [aweight=weight] if ruralres==1 & ruralgrow==0 & rasocid_binary==0 & white==1
tabstat multicult [aweight=weight] if ruralres==1 & ruralgrow==1 & rasocid_binary==1 & white==1
tabstat multicult [aweight=weight] if ruralres==1 & ruralgrow==1 & rasocid_binary==0 & white==1
tabstat multicult [aweight=weight] if ruralres==0 & ruralgrow==1 & rasocid_binary ==1 & white==1
tabstat multicult [aweight=weight] if ruralres==0 & ruralgrow==1 & rasocid_binary ==0 & white==1
tabstat multicult [aweight=weight] if ruralres==0 & ruralgrow==0 & rasocid_binary==1 & white==1
tabstat multicult [aweight=weight] if ruralres==0 & ruralgrow==0 & rasocid_binary==0 & white==1

